package com.ymatou.iapi.dguser.testcase;

import java.util.Arrays;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.ymatou.iapi.dguser.parameter.CheckBatchWxBindAndSetPwdBean;
import com.ymatou.iapi.dguser.parameter.CreateUserBackBean;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymatou.iapi.dguser.service.CheckBatchWxBindAndSetPwdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
/**
*批量检测是否绑定过微信是否设置过密码Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CheckBatchWxBindAndSetPwd{
	private static CheckBatchWxBindAndSetPwdBean checkbatchwxbindandsetpwdBean;
	private static CheckBatchWxBindAndSetPwdCall checkbatchwxbindandsetpwdCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("批量检测是否绑定过微信是否设置过密码Test");
	}

	@Before
	public void caseUp() {
		checkbatchwxbindandsetpwdBean=new CheckBatchWxBindAndSetPwdBean();
		checkbatchwxbindandsetpwdCall=new CheckBatchWxBindAndSetPwdCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(checkbatchwxbindandsetpwdCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_001() {
		Logger.start(true,"正确数据，成功");
		try {
			CreateUserBackBean u = DGUserCallService.initUsercreateNewBean();
			int userId = DGUserCallService.UserCreateNewCall(u);
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(userId));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			JsonObject asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(userId+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("false", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("true", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_002() {
		Logger.start(true,"有微信绑定信息，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(userId);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(userId));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			JsonObject asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(userId+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("true", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_003() {
		Logger.start(true,"没有设置过密码，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(u);
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(userId));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			JsonObject asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(userId+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("true", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_004() {
		Logger.start(true,"微信绑定后解绑，查询成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			DGUserCallService.unWxBind(user);
			dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(0, dgUserBindInfo.size(), "微信已经解绑");
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(user));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			JsonObject asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(user+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("false", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_005() {
		Logger.start(true,"微信绑定查询，后解绑，再查询，成功");
		try {
			UserCreateBean u = DGUserCallService.initUsercreateBean();
			int user = DGUserCallService.UserCreateCall(u);
			JsonArray dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(1, dgUserBindInfo.size(), "有绑定信息");
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(user));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			JsonObject asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(user+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("true", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
			DGUserCallService.unWxBind(user);
			dgUserBindInfo = DGUserCallService.getDGUserBindInfo(user);
			Logger.verifyEquals(0, dgUserBindInfo.size(), "微信已经解绑");
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(user));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			asJsonObject = checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject();
			Logger.verifyEquals(user+"", asJsonObject.get("userId").getAsString(), "验证userId");
			Logger.verifyEquals("false", asJsonObject.get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", asJsonObject.get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CheckBatchWxBindAndSetPwd_007() {
		Logger.start(true,"微信绑定查询，后解绑，再查询，成功");
		try {
			checkbatchwxbindandsetpwdBean.setUserIds(Arrays.asList(112312323));
			checkbatchwxbindandsetpwdCall.setData(checkbatchwxbindandsetpwdBean);
			checkbatchwxbindandsetpwdCall.callService();			
			Logger.verifyEquals("true", checkbatchwxbindandsetpwdCall.getString("success"), "验证code");
			Logger.verifyEquals("false", checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject().get("wxBindOrNot").getAsString(), "验证wxBindOrNot");
			Logger.verifyEquals("false", checkbatchwxbindandsetpwdCall.getJsonObject().getAsJsonArray("userInfoDtos").get(0).getAsJsonObject().get("setPwdOrNot").getAsString(), "验证setPwdOrNot");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}